<template>
 <div id="search">
    <div class="search">
      <input type="text" class="search-input" placeholder="歌曲/专辑/歌手" v-model="key">
    </div>
    <div class="result" v-if="searchRes!=null">
      <div class="result-group" v-if="searchRes.song!=null">
        <div class="group">
          <img class="group-img" src="../assets/touxiang.jpg">
          <p class="group-p">单曲</p>
        </div>
        <div class="result-item" v-for="item in searchRes.song.itemlist" v-on:click="play(item)">
          <p class="result-title">{{item.name}}</p>
          <p class="result-author">-{{item.singer}}</p>
        </div>

      </div>

  </div>
</template>

<script>
  export default {
    data () {
      return {
        key: '',
        
        searchRes: null,
        
      }
    },

     watch: {
      'key': {
        handler: function (key) {
          this.$http.post('users/search').then((res) => {
//            console.log(response.data)
            this.searchRes = res.data.data
          })
        },
        deep: true
      }
    },
    
    methods: {

   
         play: function (res) {
        this.$parent.playThis(res)
      },
     

    }
    
  }

</script>

<style scoped>
  .search {
    width: 100%;
    height: 60px;
    display: flex;
    flex-direction: row;
    position: fixed;
    top: 0;
    background: #fff;
    z-index: 1;
    margin-top:5%;
  }
  .search-input {
    width: 100%;
    background: #eee;
    border-radius: 5px;
    margin: 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
  }
  .search-input img {
    height: 30px;
    width: 30px;
    display: inline-block;
    margin: 0 5px;
  }
 
  .search-input input {
    width: 100%;
    height: 100%;
    border: none;
    background: #eee;
    font-size: medium;
    flex-grow: 1;
    border-radius: 5px;
    outline: none;
  }
  .search-cancel {
    height: 40px;
    width: 0px;
    margin: 10px auto;
    line-height: 40px;
    overflow: hidden;
    transition: width 0.3s;
    cursor:pointer;
  }
  .search-cancel-show {
    width: 55px;
  }
  .hotkey {
    margin-top: 60px;
    margin-bottom: 50px;
    background: #eeeeee;
    display: flex;
    flex-direction: column;
  }
  .hotkey ul {
    list-style: none;
    background: #fff;
  }
  .hotkey ul li {
    height: 40px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    cursor: pointer;
  }
  .hotkey ul li .hotkey-index {
    padding-right: 10px;
  }
  .hotkey ul li .hotkey-k {
    flex-grow: 1;
  }
  .search-history {
    display: flex;
    flex-wrap: wrap;
    background: #fff;
    padding: 0 10px;
    max-height: 66px;
  }
  .search-history .search-history-item {
    margin: 5px;
    padding: 0 3px;
    border: 1px solid #000;
    border-radius: 14px;
    cursor:pointer;
  }
  .result {
    margin-top: 60px;
    margin-bottom: 50px;
    background: #eeeeee;
    display: flex;
    flex-direction: column;
  }
  .result-group {
    background: #ffffff;
  }
  .group {
    display: flex;
    flex-direction: row;
    height: 40px;
    align-items: flex-end;
    padding-bottom: 5px;
    padding-left: 10px;
    background: #eeeeee;
  }
  .group-img {
    width: 25px;
    height: 25px;
  }
  .group-p {
    margin-left: 10px;
  }
  .result-item {
    display: flex;
    background: #ffffff;
    border-bottom: 1px #eeeeee solid;
    flex-direction: row;
    margin-left: 10px;
    padding-left: 10px;
    height: 40px;
    align-items: center;
    cursor: pointer;
  }
  .result-item .result-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .result-item .result-author {
    color: #929292;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex-grow: 1;
  }
  .album-item {
    height: 40px;
    display: flex;
    flex-direction: row;
    border-bottom: #eeeeee 1px solid;
    padding: 10px 10px;
    align-items: center;
    cursor:pointer;
  }
  .album-img {
    height: 40px;
    width: 40px;
    border-radius: 5px;
  }
  .album-info {
    display: flex;
    flex-direction: column;
    padding-left: 15px;
  }
  .album-name {
    font-size: 14px;
    line-height: 20px;
  }
  .album-author {
    font-size: 12px;
    color: #929292;
    line-height: 20px;
  }
  .songs-action-button {
    height: 20px;
    width: 20px;
    margin-right: 10px;
  }
  .singer-item {
    height: 40px;
    display: flex;
    flex-direction: row;
    padding: 5px 10px;
    align-items: center;
    cursor:pointer;
  }
  .singer-img {
    height: 40px;
    width: 40px;
    border-radius: 50%;
  }
  .singer-p {
    display: flex;
    border-bottom: 1px #eeeeee solid;
    height: 40px;
    align-items: center;
    padding: 3px 10px;
    flex-grow: 1;
  }
  .mv-item {
    display: flex;
    flex-direction: column;
    border-bottom: #eeeeee 1px solid;
    padding: 10px;
    cursor:pointer;
  }
  .mv-name {
    font-size: 14px;
    line-height: 20px;
  }
  .mv-author {
    font-size: 12px;
    color: #929292;
    line-height: 20px;
  }
  .action-button {
    width: 20px;
    height: 20px;
    padding: 10px;
  }
  .action-button img {
    width: 20px;
  }
  @media screen and (min-width: 68vh) {
    .search {
      width: 68vh;
    }
  }
</style>